﻿<?php
$edit_url	=	"?act=list_song";
if ($del_id) {
	acp_check_permission('del_media');
	if ($_POST['submit']) {
		$mysql->query("DELETE FROM ".$tb_prefix."data WHERE m_id = '".$del_id."'");
		echo "Đã xóa xong <meta http-equiv='refresh' content='0;url=".$edit_url."'>";
		exit();
	}
	?><table align=center><form method="post">Bạn có muốn xóa không ??????<br><center><input value="Có" name=submit type=submit class=submit></center></form></table><?
}
// EDIT SONGS
if($mode == 'edit') {
acp_check_permission('edit_media');
	if(is_numeric($id)) {
		$sql 			= "SELECT * FROM ".$tb_prefix."data WHERE m_id = $id";
		$query 			= $mysql->query($sql);
		if($mysql->num_rows($query)) {
		$row 			= $mysql->fetch_array($query);
		
		$song_ID 		= $id;
		$song_NAME 		= $row['m_title'];
		
		$singer_ID 		= $row['m_singer'];
		$singer_NAME 	= m_get_data('SINGER',$singer_ID);
		
		$album_ID 		= $row['m_album'];
		$album_NAME 	= m_get_data('ALBUM',$album_ID);
		
		$cat_ID 		= $row['m_cat'];
		$cat_NAME 		= m_get_data('CAT',$cat_ID);
		
		$song_WIDTH 	= $row['m_width'];
		$song_HEIGHT 	= $row['m_height'];
		
		$song_URL 		= $row['m_url'];
		$song_LOCAL 	= "<input value=1".(($row['m_is_local'])?' checked':'')." type=checkbox class=checkbox name=local>";
		
		$song_LYRIC 	= $row['m_lyric'];
		$action			= "?act=song&mode=edit&id=$song_ID";
		if(isset($_POST['submit'])) {
			if($_POST['song'] == "" || $_POST['url'] == "") {
				echo " Chưa nhập đủ thông tin ";
			}
			else { 	
				$song		 = m_htmlchars(stripslashes(trim(urldecode($_POST['song']))));
				$song_ascii  = strtolower(utf8_to_ascii($song));
				if($_POST['new_singer'] && $_POST['singer_type']) {
					$new_singer 	 = m_htmlchars(stripslashes(trim(urldecode($_POST['new_singer']))));
					$singer_type = $_POST['singer_type'];
					$singer = acp_quick_add_singer($new_singer,$singer_type);
				}
				else {
				$singer 	 = $_POST['singer'];
				}
				$album		 = $_POST['album'];
				$cat		 = $_POST['cat'];
				$width		 = m_htmlchars(stripslashes(trim(urldecode($_POST['width']))));
				$height		 = m_htmlchars(stripslashes(trim(urldecode($_POST['height']))));
				$url		 = m_htmlchars(stripslashes(trim(urldecode($_POST['url']))));
				$local		 = $_POST['local'];
				$lyric		 = m_htmlchars(stripslashes(trim(urldecode($_POST['lyric']))));
				$mysql->query("UPDATE ".$tb_prefix."data SET
					m_title			=  	'".$song."',
					m_title_ascii 	= 	'".$song_ascii."',
					m_singer		= 	'".$singer."',
					m_album			=	'".$album."',
					m_cat			=	'".$cat."',
					m_width			=	'".$width."',
					m_height		=	'".$height."',
					m_url			=	'".$url."',
					m_is_local		=	'".$local."',
					m_lyric			=	'".$lyric."' 
			  WHERE m_id 			= 	'".$id."'
				");
				echo "<script language='JavaScript'>{ window.parent.location='?act=song&mode=edit&id=$id' }</script>";
			}
		}
	}
	if(!$mysql->num_rows($query)) {
		die("Bài hát này chưa có trong data");
	}
}
include("templates/song.html");
}
// ADD SONGS
if($mode == 'add') {
acp_check_permission('add_media');
	if(isset($_POST['submit'])) {
		if($_POST['song'] == "" || $_POST['url'] == "") {
			echo " Chưa nhập đủ thông tin ";
		}
		if($_POST['song'] && $_POST['url']) { 	
			$song		 = m_htmlchars(stripslashes(trim(urldecode($_POST['song']))));
			$song_ascii  = strtolower(utf8_to_ascii($song));
				if($_POST['new_singer'] && $_POST['singer_type']) {
					$new_singer 	 = m_htmlchars(stripslashes(trim(urldecode($_POST['new_singer']))));
					$singer_type = $_POST['singer_type'];
					$singer = acp_quick_add_singer($new_singer,$singer_type);
				}
			else {
			$singer 	 = $_POST['singer'];
			}
			$album		 = $_POST['album'];
			$cat		 = $_POST['cat'];
			$width		 = m_htmlchars(stripslashes(trim(urldecode($_POST['width']))));
			$height		 = m_htmlchars(stripslashes(trim(urldecode($_POST['height']))));
			$url		 = m_htmlchars(stripslashes(trim(urldecode($_POST['url']))));
			$local		 = $_POST['local'];
			$lyric		 = m_htmlchars(stripslashes(trim(urldecode($_POST['lyric']))));
			$user_id	 = $_SESSION['admin_id'];
			$date		 = date("Y-m-d",NOW);
			$time		 = time();
			$type		 = acp_type($url);
			$action		 = "?act=song&mode=add";
			$mysql->query("INSERT INTO ".$tb_prefix."data (m_title,m_title_ascii,m_singer,m_album,m_cat,m_poster,m_lyric,m_type,m_date,m_time,m_url,m_is_local,m_width,m_height) 
						 VALUES ('".$song."','".$song_ascii."','".$singer."','".$album."','".$cat."','".$user_id."','".$lyric."','".$type."','".$date."','".$time."','".$url."','".$local."','".$width."','".$height."')");
			
echo "<center><font color='red'>Đã thêm xong</font></center> <meta http-equiv='refresh' content='0;url=$link'>";

		}
	}		
include("templates/song.html");	
}
if($mode == 'multi_add_song') {
	include("multi_song.php");
}
?>